import { StepData, StepSelectData } from "../const/datas";
import React from "react";
import { locationReplace } from "./LocationUtil";
import * as locations from "../const/locations";
import SingleInput from "../screen/autheninfo/components/SingleInput";
import Select from "../screen/autheninfo/components/Select";
import { getID } from "./StorageUtil";
import LocalStorage from "../Storage";

// let formInfo = JSON.parse(LocalStorage.getItem(formItem));
export function renderForm(item) {
  let list = item ? item : null;
  if (Array.isArray(item)) {
    return list.map((item, index) => {
      if (StepData[item["id"]]["isSelect"] !== true) {
        //判断是否input
        if (item["id"] !== "55") {
          //判断是否自定义标签
          if (Array.isArray(StepData[item["id"]])) {
            //判断id对应stepdata是否数组
            return StepData[item["id"]].map((ele, index) => {
              return (
                <SingleInput
                  key={index}
                  ref={ele["name"]}
                  inputType={ele["type"]}
                  title={ele["title"]}
                  name={ele["name"]}
                  placeholder={ele["placeholder"]}
                  visibility={item["R"] === "1"}
                />
              );
            });
          }
          return (
            // 非数组
            <SingleInput
              key={index}
              ref={StepData[item["id"]]["name"]}
              inputType={StepData[item["id"]]["type"]}
              title={StepData[item["id"]]["title"]}
              name={StepData[item["id"]]["name"]}
              placeholder={StepData[item["id"]]["placeholder"]}
              visibility={item["R"] === "1"}
            />
          );
        } else {
          //自定义标签
          return (
            <SingleInput
              key={index}
              ref={item["T"]}
              inputType={"text"}
              title={item["N"]}
              name={item["T"]}
              visibility={item["R"] === "1"}
            />
          );
        }
      } else {
        if (item["id"] === "10") {
          //判断是否选择地区
        } else {
          return (
            //其他select
            <Select
              key={index}
              ref={StepData[item["id"]]["name"]}
              title={StepData[item["id"]]["title"]}
              name={StepData[item["id"]]["name"]}
              placeholder={StepData[item["id"]]["placeholder"]}
              visibility={item["R"] === "1"}
              options={StepSelectData[item["id"]]}
            />
          );
        }
      }
    });
  } else {
    return locationReplace(locations.LOGIN, "");
  }
}
export function getName(obj) {
  let checkName = { id: getID() };
  for (const item in obj) {
    let value = obj[item].state.value;
    checkName[item] = value;
  }
  return checkName;
}
